package hy.controller;

import hy.beans.AjaxRestult;
import hy.dao.EmpMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    EmpMapper dao;
    //rest APi：put--修改，post--添加，
    @GetMapping("/emps")
    public AjaxRestult showEmps(){
        AjaxRestult rs=new AjaxRestult();
        List list=dao.selectAllEmp();
        if(!list.isEmpty()){
            rs.setSuccess(true);
            rs.setData(list);
        }
        return rs;
    }


    @DeleteMapping("/emps")
    public AjaxRestult deleteEmpById(Integer id){
        AjaxRestult rs=new AjaxRestult();
        int r=dao.deleteEmpById(id);
        rs.setSuccess(r>0);
        return rs;
    }
}